feat(hooks): add V4 checkpoint writer for long DeepSeek V4 sessions#5438
Open
EvangelosMoschou wants to merge 2 commits into
Open
feat(hooks): add V4 checkpoint writer for long DeepSeek V4 sessions#5438EvangelosMoschou wants to merge 2 commits into
EvangelosMoschou wants to merge 2 commits into
Conversation
DeepSeek V4 loses coherence on long sessions. MiMo Code's research showed
that periodic state extraction at intervals keeps context lean and enables
crash recovery. This is a simplified version: every 20 tool calls, writes
a checkpoint file with session ID, model, tool call count, and timestamp.
The hook:
- Tracks V4 sessions from message.updated events
- Every 20 tool calls, writes checkpoint to .omo/checkpoints/{sessionID}.json
- Non-V4 sessions are unaffected (zero overhead)
- Gated behind disabled_hooks as 'v4-checkpoint-writer'
TDD: 4 tests (20 calls -> checkpoint, 19 -> no checkpoint, non-V4 -> none, 40 -> 2nd checkpoint).
All existing tool-guard composition tests still pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DeepSeek V4 loses coherence on long sessions. MiMo Code's research showed that periodic state extraction at intervals keeps context lean and enables crash recovery.
Fix
New
v4-checkpoint-writerhook (ToolGuard tier) that:message.updatedevents.omo/checkpoints/{sessionID}.jsonCheckpoint file format:
{ "sessionID": "ses_abc123", "modelID": "deepseek/deepseek-v4-pro", "toolCallCount": 20, "lastToolName": "bash", "timestamp": "2026-06-19T17:30:00.000Z" }TDD Evidence
4 tests covering all paths:
All existing tool-guard composition tests still pass.
Research backing
From MiMo Code's architecture (which beat Claude Code at >200-step tasks):
Files
packages/omo-opencode/src/hooks/v4-checkpoint-writer/hook.ts(new) -- hook implementationpackages/omo-opencode/src/hooks/v4-checkpoint-writer/index.ts(new) -- barrel exportpackages/omo-opencode/src/hooks/v4-checkpoint-writer/hook.test.ts(new) -- 4 testspackages/omo-opencode/src/hooks/index.ts-- barrel export addedpackages/omo-opencode/src/plugin/hooks/create-tool-guard-hooks.ts-- hook registeredpackages/omo-opencode/src/config/schema/hooks.ts-- hook name added toHookNameSchemaUsage
The hook is always on (can be disabled via
disabled_hooks):{ "disabled_hooks": ["v4-checkpoint-writer"] }Complements PR #5403 (DeepSeek V4 Sisyphus + compaction) and PR #5437 (V4 verification gate).
Conflict note
This PR and #5437 (V4 verification gate) both modify the same 3 files:
hooks.ts,hooks/index.ts, andcreate-tool-guard-hooks.ts. Whichever merges first, the other will need a rebase to resolve merge conflicts in those files. If you'd like me to batch-rebase one onto the other before merging, let me know.Summary by cubic
Add a checkpoint writer hook for DeepSeek V4 that saves session state every 20 tool calls to keep long sessions coherent and enable crash recovery. Non‑V4 sessions are unaffected.
v4-checkpoint-writerthat tracks V4 sessions frommessage.updatedevents and writes checkpoints every 20 tool calls to<workspace>/.omo/checkpoints/{sessionID}.json(or~/.omo/checkpointswhen no workspace), including session ID, model ID, tool call count, last tool, and timestamp.disabled_hooks: ["v4-checkpoint-writer"].Written for commit 205693a. Summary will update on new commits.